package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.io.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.sl.report.ReportCommon;

import org.apache.log4j.Logger;

public class AccessoriesStoreActivity
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(AccessoriesStoreActivity.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] params = oCtx.getActivityParameter().split(":");
		
		String oTransid = (String)oCtx.getField("transid");
		File[] vAccessories = (File[])oCtx.getField(params[0]);
		
		if (null != vAccessories)
		{
			String[] vAccessoriesFileNames = (String[])oCtx.getField(params[1]);
			
			for (int i = 0; i < vAccessories.length; ++i)
			{
				File dir = new File(ReportCommon.JASPER_DIR + oTransid);
				File dest = new File(ReportCommon.JASPER_DIR + oTransid + "/" + vAccessoriesFileNames[i]);
				
				if (!dir.exists())
					dir.mkdirs();
				
				if (dest.exists())
					dest.delete();
				
				if (!vAccessories[i].renameTo(dest))
					throw new ActivityException(oCtx, "accessoriesStore.err.cannotBeStored");
			}
		}
	}
}
